package com.formiaomiao.demain.activity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.formiaomiao.demain.R;
import com.formiaomiao.demain.base.BaseActivity;
import com.formiaomiao.demain.base.HomeFragmentAdapter;
import com.formiaomiao.demain.fragment.DemainAllFragment;
import com.formiaomiao.demain.fragment.DemainFollowFragment;
import com.formiaomiao.demain.fragment.FollowFansFragment;
import com.formiaomiao.demain.fragment.FollowUserFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FollowActivity extends BaseActivity {

    @BindView(R.id.iv_class_back)
    ImageView ivClassBack;
    @BindView(R.id.tv_class_name)
    TextView tvClassName;
    @BindView(R.id.tv_class_submit)
    TextView tvClassSubmit;
    @BindView(R.id.tab)
    TabLayout tab;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private String[] mTitles = {"我关注的人", "我的粉丝"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_follow);
        ButterKnife.bind(this);
        ViewInit();
    }

    private void ViewInit(){
        tvClassName.setText("关注");
        DataInit();
    }

    @SuppressLint("ResourceAsColor")
    private void DataInit() {
        HomeFragmentAdapter adapter = new HomeFragmentAdapter(getSupportFragmentManager());
        //设置tab的文字
        ArrayList<String> titles = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            titles.add(mTitles[i]);
        }
        adapter.setTitles(titles);
        //设置tab对应得fragment
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(FollowUserFragment.newInstance());
        fragments.add(FollowFansFragment.newInstance());
        adapter.setFragments(fragments);
        viewPager.setAdapter(adapter);
        tab.setupWithViewPager(viewPager);
        //设置默认第一个为选中的tab
        tab.getTabAt(0).isSelected();
        //自定义tab样式
        for (int i = 0; i < mTitles.length; i++) {
            //获取某个tab(这个API对应自定义TabLayout很重要)
            TabLayout.Tab tabAt = tab.getTabAt(i);
            //加载自定义的tab布局
            View inflate = View.inflate(FollowActivity.this, R.layout.tab_demain_title_layout, null);
            TextView mTabCustomText = (TextView) inflate.findViewById(R.id.tab_custom_text);
            mTabCustomText.setText(mTitles[i]);
            //把自定义的tab布局设置给对应的tab
            tabAt.setCustomView(inflate);
        }
    }

    @OnClick(R.id.iv_class_back)
    public void onViewClicked() {
        finish();
    }
}
